<cfcomponent output="false">
	
	<!--- --->
	
	<cffunction name="renderCalendar" access="public" output="true" returntype="string">
		
		<cfset var local = {} />
		
		<cfset local.googleCalendarIDs = {} />
		<cfset local.options = $.run.it('optionService.getOptions',{key="calendar"}) />
		<cfset local.userCalendarIDs = "" />
		
		<cfif local.options.refresh_token neq "">
			<cfset local.access_token = $.run.it('googleService.getAccessToken') />
			<cfif local.access_token neq ''>
				<!--- build calendarList --->
				<cfset local.userCalendarIDs = $.run.it('googleService.getUserCalendars') />
				<cfset local.googleCalendarIDs = $.run.it('googleService.getCalendars',{access_token=local.access_token}) />
				
				<cfset local.labels = [] />
				<cfset local.values = [] />
				
				<cfloop collection="#local.googleCalendarIDs#" item="local.item">
					<cfset arrayAppend(local.labels,local.googleCalendarIDs[local.item]) />
					<cfset arrayAppend(local.values,local.item) />
				</cfloop>
			</cfif>
		</cfif>
		<cfset local.first = "first" />

		<cfsavecontent variable="local.result">
			#$.render.form(name="calendar_options_form",method="calendarController.saveCalendarOptions")#
				<cfif local.options.refresh_token neq ''>
					<div class="widget-title sub #local.first#">Google Calendar</div>
					<input type="hidden" name="key" value="calendar" />
					<input type="hidden" name="oldIDs" value="#local.userCalendarIDs#" />
					<!--- here because the checkboxes may have nothing checked --->
					<input type="hidden" name="google_calendar_ids" value="#local.options.craftivity_calendar_id#" />
					<cfset local.ids = structKeyList(local.googleCalendarIDs) />
					<cfset local.values = "" />
					
					<cfloop list="#local.ids#" index="local.i">
						<cfset local.values = listAppend(local.values,local.googleCalendarIDs[local.i].name) />
					</cfloop>
					
					#$.run.it('craftivityView.renderCheckboxes',{
						name="google_calendar_ids",
						label="Calendars",
						values="#local.ids#",
						labels="#local.values#",
						value="#local.userCalendarIDs#",
						disabled="#local.options.craftivity_calendar_id#"
					})#
					
					#$.run.it('craftivityView.renderField',{
						name="connection",
						field=#$.render.img(path='craftivity/nothing.png',class="google_disconnect",onclick="Calendar.disconnectGoogleCalendar();")#
					})#
					
					<cfif local.options.last_synced_on neq ''>
						<cfsavecontent variable="local.update_link">
							<button type="button" style="margin:0px 0px 8px 0px;" class="small grey" onclick="Main.func('calendarController','resyncGoogleCalendar','','Resync Calendar?');">Resync</button>
						</cfsavecontent>
					</cfif>
				
					<cfif local.options.initial_sync_complete eq true>
						#$.run.it('craftivityView.renderField',{
							name="Resync",
							instructions="Use this to correct any syncing issues",
							field='<div class="last-sync">#local.update_link#</div>'
						})#
					<cfelse>
						#$.run.it('craftivityView.renderField',{
							name="Resync",
							field='<div class="last-sync">update in progress...</div>'
						})#
					</cfif>
				</cfif>
				
				#$.run.it('optionView.renderCalendarCategories')#

				<div class="buttons">
					<button class="right red">Save</button>
				</div>
			</form>
			
			<!--- hidden forms --->
			<cfset local.date = $.link.getArg(cgi.http_referer,'date') />
			<cfif local.date eq "true">
				<cfset local.date = "" />
			</cfif>
			
			#$.render.form(name='disconnect_calendar',method='calendarController.disconnectCalendar')#
				<input type="hidden" name="date" value="#local.date#" />
				<input type="hidden" name="refresh_token" value="#options.refresh_token#" />
			</form>

		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderWorkweek" access="public" output="true" returntype="string">
		
		<cfset var local = {} />
		
		<cfset local.options = $.run.it('optionService.getOptions',{key="workweek"}) />
		
		<cfsavecontent variable="local.result">
			#$.render.form(name="workweek_options_form",method="optionController.saveOptions")#
				<input name="key" type="hidden" value="workweek" />
				<div class="widget-title sub first">Work Days</div>
				#$.run.it('craftivityView.renderWeekdayCheckboxes',{value=local.options.workdays,name="workdays"})#
				
				<div class="widget-title sub first">Beginning of week</div>
				#$.run.it('craftivityView.renderSelect',{label="day",name="first_day",blank="false",value=local.options.first_day,values="0,1,2,3,4,5,6",labels="Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday"})#

				<div class="widget-title sub first">Work Hours</div>
				#$.run.it('craftivityView.renderSelect',{name="start_time",blank="false",value=local.options.start_time,values="0,1,2,3,4,5,6,7,8,9,10,11,12",labels="12 AM,1 AM,2 AM,3 AM,4 AM,5 AM,6 AM,7 AM,8 AM,9 AM,10 AM,11 AM,12 PM"})#
				#$.run.it('craftivityView.renderSelect',{name="end_time",blank="false",value=local.options.end_time,values="13,14,15,16,17,18,19,20,21,22,23,24",labels="1 PM,2 PM,3 PM,4 PM,5 PM,6 PM,7 PM,8 PM,9 PM,10 PM,11 PM,12 AM"})#
				
				#_renderWorkweekCategories()#
				
				<div class="buttons">
					<button class="right red">Save</button>
				</div>
			</form>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderWorkweekCategories" access="public" output="true" returntype="string">
		
		<cfset var local = {} />

		<cfsavecontent variable="local.result">
			#$.render.form(name="workweek_options_form",method="optionController.saveOptions")#
				<input name="key" type="hidden" value="workweek" />

				#_renderWorkweekCategories()#
				
				<div class="buttons">
					<button class="right red">Save</button>
				</div>
			</form>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="_renderWorkweekCategories" access="private" output="true" returntype="string">
		
		<cfset var local = {} />
		
		<cfset local.options = $.run.it('optionService.getOptions',{key="workweek"}) />
		
		<cfsavecontent variable="local.result">
			<div class="widget-title sub first">Categories</div>
			<div class="workweek-category-options">
				<cfloop list="#local.options.categories#" item="local.category" index="local.i">
					<cfsavecontent variable="local.input">
						<div class="optionCategories we-cat#local.i#b"></div>
						<input name="categories" value="#local.category#" validate="required" style="width:161px;">
					</cfsavecontent>
					#$.run.it('craftivityView.renderField',{field="#local.input#",name="categories",label="Category #local.i#",value=local.category,validate="required"})#
				</cfloop>
			</div>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="_renderWorkweekCategories" access="private" output="true" returntype="string">
		
		<cfset var local = {} />
		
		<cfset local.options = $.run.it('optionService.getOptions',{key="workweek"}) />
		
		<cfsavecontent variable="local.result">
			<div class="widget-title sub first">Categories</div>
			<div class="workweek-category-options">
				<cfloop list="#local.options.categories#" item="local.category" index="local.i">
					<div class="form-input">
						<div class="form-input-label"><div class="optionCategories we-cat#local.i#b"></div></div>
						<div class="form-input-value">
							<input name="categories" value="#local.category#" validate="required">
						</div>
					</div>
				</cfloop>
			</div>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderCalendarCategories" access="public" output="true" returntype="string">
		
		<cfset var local = {} />
		
		<cfsavecontent variable="local.result">
			<div class="widget-title sub first">Event Categories</div>
			<div class="workweek-category-options">
				<cfloop list="#request.session.user.event_categories#" item="local.category" index="local.i">
					<div class="form-input">
						<div class="form-input-label"><div class="optionCategories cat#local.i#"></div></div>
						<div class="form-input-value">
							<input name="categories" value="#local.category#" validate="required">
						</div>
					</div>
				</cfloop>
			</div>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
		
	<cffunction name="renderOption" access="public" output="true" returntype="string">
		<cfargument name="key" required="true" />
		
		<cfset var local = {} />
		
		<cfsavecontent variable="local.result">
			<div class="widget short hidden options edit">
				<div class="widget-title">
					<i class="fa fa-times close-options" onclick="Main.toggleOptions('#arguments.key#');"></i>
					<i class="fa fa-gears"></i>
					Options
				</div>
				<div class="unloadedOption">
					<i class="fa fa-spinner fa-spin"></i>Loading...
				</div>
			</div>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
</cfcomponent>